package com.xzx;

import jakarta.jms.*;
import org.junit.Test;

/**
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2025/9/10 14:50
 */
public class MessagePropertiesTest {

    @Test
    public void test() throws Exception {
        Connection connection = AmqUtil.getConnection();
        Session session = connection.createSession();
        Queue queue = session.createQueue("xzx");
        MessageProducer producer = session.createProducer(queue);
        TextMessage message = session.createTextMessage("hello world");
        message.setStringProperty("k1", "v1");
        message.setIntProperty("k2", 2);
        producer.send(message);
        session.close();
        AmqUtil.closeConnection(connection);
    }

    @Test
    public void test2() throws Exception {
        Connection connection = AmqUtil.getConnection();
        Session session = connection.createSession();
        Queue queue = session.createQueue("xzx");
        MessageConsumer consumer = session.createConsumer(queue);
        TextMessage message = (TextMessage) consumer.receive();
        System.out.println(message.getText());
        System.out.println(message.getStringProperty("k1"));
        System.out.println(message.getIntProperty("k2"));
        session.close();
        AmqUtil.closeConnection(connection);
    }
}
